#!/usr/bin python3
# -*- coding:UTF-8 -*-
# Author: nigo
import requests

def address2location(address):
    """
    地址转换为精纬度
    address:地址
    return: lon,lat
    """
    url = 'https://restapi.amap.com/v3/geocode/geo?' # 高德地图接口
    params = {
        'address':address, # 地址
        "key":'你的key' # 注册申请key
    }
    response = requests.get(url,params=params)
    json_str = response.json()
    if json_str['geocodes']:
        location = json_str['geocodes'][0]['location']
        location = location.split(',')
        return location[0], location[1]
    return '',''

if __name__ == "__main__":
    address = '四川省成都市天府广场'
    lon,lat = address2location(address)
    print(lon,lat)

